class IngressosController < ApplicationController

  def initialize
    @gruposingressos = Ingressogrupo.find :all
  end
  # GET /ingressos
  # GET /ingressos.xml
  def index
    @ingressos = Ingresso.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @ingressos }
    end
  end

  # GET /ingressos/1
  # GET /ingressos/1.xml
  def show
    @ingresso = Ingresso.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @ingresso }
    end
  end

  # GET /ingressos/new
  # GET /ingressos/new.xml
  def new
    @ingresso = Ingresso.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @ingresso }
    end
  end

  # GET /ingressos/1/edit
  def edit
    @ingresso = Ingresso.find(params[:id])
  end

  # POST /ingressos
  # POST /ingressos.xml
  def create
    puts 'ok'
    @ingresso = Ingresso.new(params[:ingresso])

    @ingresso = modifica @ingresso,params[:ingresso]


    respond_to do |format|
      if @ingresso.save
        flash[:notice] = 'Ingresso was successfully created.'
        format.html { redirect_to(ingressos_url) }
        format.xml  { render :xml => @ingresso, :status => :created, :location => @ingresso }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @ingresso.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /ingressos/1
  # PUT /ingressos/1.xml
  def update
    @ingresso = Ingresso.find(params[:id])

    respond_to do |format|
      if @ingresso.update_attributes(params[:ingresso])
        flash[:notice] = 'Ingresso was successfully updated.'
        format.html { redirect_to(ingressos_url) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @ingresso.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /ingressos/1
  # DELETE /ingressos/1.xml
  def destroy
    @ingresso = Ingresso.find(params[:id])
    @ingresso.destroy

    respond_to do |format|
      format.html { redirect_to(ingressos_url) }
      format.xml  { head :ok }
    end
  end
end
